import java.util.concurrent.*;

//线程池实现
class MyThreadPool {

   BlockingQueue<Runnable> que = new LinkedBlockingQueue<>();

   public void submit(Runnable runnable) {
       try {
           que.put(runnable);
       } catch (InterruptedException e) {
           e.printStackTrace();
       }
   }

   public MyThreadPool(int n) {
       for (int i = 0; i < n; i++) {
           Thread t = new Thread(() -> {
               while (!Thread.currentThread().isInterrupted()) {
                   try {
                       Runnable runnable = que.take();
                       runnable.run();
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                       break;
                   }
               }
           });
        t.start();
       }
   }

}

public class Demo {

    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(10);
        //安排任务
        executor.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("hello");
            }
        });
    }
    public static void main1(String[] args) {
        MyThreadPool myThreadPool = new MyThreadPool(10);

        for (int i = 0; i < 100; i++) {
            myThreadPool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("Hello");
                }
            });
        }
    }


}
